﻿using System.Collections.Generic;
using System.Net.Http;
using System.Threading.Tasks;

using ManageSystemClient.Record;

namespace ManageSystemClient.HttpService
{
    internal class ManageService
    {
        private readonly HttpServiceBase baseService;

        public ManageService(HttpServiceBase baseService)
        {
            this.baseService = baseService;
        }

        public async Task<Student> GetStudentAsync(uint id) =>
            await baseService.SendAsync<Student>($"/student/id/{id}", HttpMethod.Get);

        public async Task<List<Student>> GetStudentByNameAsync(string name) =>
            await baseService.SendAsync<List<Student>>($"/student/?name={name}", HttpMethod.Get);

        public async Task<List<Student>> GetStudentByMajorAsync(string major) =>
            await baseService.SendAsync<List<Student>>($"/student/?major={major}", HttpMethod.Get);

        public async Task<List<Student>> GetStudentsAsync() =>
            await baseService.SendAsync<List<Student>>("/student/all", HttpMethod.Get);

        public async Task AddStudentAsync(Student student) =>
            await baseService.SendAsync("/student/add", HttpMethod.Post, student);

        public async Task ModifyStudentAsync(Student student) =>
            await baseService.SendAsync($"/student/reset/{student.StudentId}", HttpMethod.Put, student);

        public async Task DeleteStudentAsync(uint id) =>
            await baseService.SendAsync($"/student/delete/{id}", HttpMethod.Delete);

    }
}
